import Vue from 'vue'

import Vuex from 'vuex'

// 通过Vue加载这个插件
Vue.use(Vuex)

const actions = {
    jia(store,value){
        // console.log("add的dispatch被触发了",store,value);
        store.commit("JIA",value);
    },
    jian(store,value){
        store.commit("JIAN",value);
    },
    oddAdd(store,value){
        store.commit("ODDADD",value);
    },
    waitAdd(store,value){
        store.commit("WAITADD",value);
    },


}

const mutations = {
    JIA(state,value){
        // console.log("add的commit被触发了",a,b);
        state.count += value
    },
    JIAN(state,value){
        state.count -= value
    },
    ODDADD(state,value){
        if(state.count % 2 != 0){
            state.count += value
        }
    },
    WAITADD(state,value){
        setTimeout(()=>{
            state.count += value
        },500)
    },
}

const state = {
    count:0,
    studentName:'学生名称',
    schoolName:'二圣小学',
    smallName:'xfj'
}

const getters = {
    ncount(){
        return state.count * 10
    }
}


export default new Vuex.Store({
    actions,
    mutations,
    state,
    getters
})